<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>

	<script type="text/javascript">
	 	dojo.require("dijit.Editor");
		dojo.require("dijit.form.ValidationTextBox");
		dojo.require("dijit.form.FilteringSelect");
		dojo.require("dijit.form.DateTextBox");
		dojo.require("dijit.form.RadioButton");
		dojo.require("dojox.validate.regexp");
		dojo.require("dojo.parser");
	</script>
		
	<script type="text/javascript">
		$(document).ready(function() {
			$("input[name='btnCancel']").click(function() {
				var uri = ISS.lang.getBasePath()+'index.php';
				window.location = uri;
			});

			$("input[name='btnAddClub']").click(function() {
				var uri = ISS.lang.getBasePath()+'index.php/member/profile/add_club/';
				ISS.Ajax.Caller.request(uri, {id: dijit.byId("cboClub").getValue()});	
			});

			$("input[name='btnAddGene']").click(function() {
				var uri = ISS.lang.getBasePath()+'index.php/member/profile/add_gene/';
				ISS.Ajax.Caller.request(uri, {id: dijit.byId("cboGene").getValue()});	
			});			

			$(".actionDelClub").click(function() {
				if (confirm('คุณต้องการลบคลับเพลง ใช่หรือไม่?')) {
					var uri = $(this).attr('href'); 
					ISS.Ajax.Caller.request(uri, null);	
				}	
				return false;
			});

			$(".actionDelGene").click(function() {
				if (confirm('คุณต้องการลบแนวเพลง ใช่หรือไม่?')) {
					var uri = $(this).attr('href'); 
					ISS.Ajax.Caller.request(uri, null);	
				}	
				return false;
			});
			
		}); 
	</script>
	
	<?php 	
	if (!empty($form['txtPicture'])) {
		echo html::Stylesheet(
			array
			(
				'media/css/profile_picture_block.css',
			),
			array
			(
				'screen',
			)
		);	
	}
	else {
		echo html::Stylesheet(
			array
			(
				'media/css/profile_block.css',
			),
			array
			(
				'screen',
			)
		);	
	}
	?>
	
<div id="mainCont">
	<?php print form::open_multipart('member/profile/save');?>
		<div id="profileBlock">
			<div id="profileBlockTop"> 
				<h3>ข้อมูลสมาชิก</h3>
				<p><?php echo (empty($status)) ? 'กรุณากรอกข้อมูลให้ครบสมบูรณ์' : $status;?></p>
			</div>
			<div id="profileBlockBody">
				<table>
					<tr>
						<td><div class="mandatory">ชื่อ::</div></td>
						<td>
							<select style="width:80px"
								dojoType="dijit.form.FilteringSelect"
								value="<?php echo html::specialchars($form['cboPrefix']) ?>"
								name="cboPrefix"
							    required="true"								
								invalidMessage="กรณาระบุคำนำหน้า"
								autoComplete="true">
								<?php foreach ($master_prefixs as $prefix): ?>
								<option value="<?php echo $prefix['id']; ?>"><?php echo html::specialchars($prefix['title']); ?></option>
							    <?php endforeach ?>							
							</select>
													
							<input type="text" name="txtFirstname" value="<?php echo html::specialchars($form['txtFirstname']) ?>"/>
							<input type="text" name="txtLastname" value="<?php echo html::specialchars($form['txtLastname']) ?>"/>
						</td>
					</tr>
					
					<tr>
						<td>วันเกิด::</td>
						<td>
							<input id="txtBirthdate" type="text" name="txtBirthdate" value="<?php echo html::specialchars($form['txtBirthdate']) ?>"
								dojoType="dijit.form.DateTextBox"
							/>
						</td>
					</tr>
					<tr>
						<td><div class="mandatory">เพศ::</div></td>
						<td>
							<?php foreach ($master_sexs as $sex): ?>
								<input type="radio" name="rdoSex" dojoType="dijit.form.RadioButton" value="<?php echo $sex['id'];?>" 
								<?php
									if (empty($form['rdoSex'])) { 
										echo ($sex['id']==1)? 'checked="checked"' : '';
									}
									else {
										echo ($sex['id']==$form['rdoSex'])? 'checked="checked"' : '';
									} 
								?>>
								<?php echo html::specialchars($sex['title']); ?>
								</input>
							<?php endforeach ?>
						</td>
					</tr>
					<tr>
						<td><div class="mandatory">email::</div></td>
						<td>
							<input type="text" 
								name="txtEmail" 
								value="<?php echo html::specialchars($form['txtEmail']) ?>"
								id="txtEmail" 
								size="30" 
								dojoType="dijit.form.ValidationTextBox" 
								regExp=".*@.*"/>
						</td>
					</tr>
					<tr>
						<td>คำถามกันลืมรหัสผ่าน::</td>
						<td>
							<select
								dojoType="dijit.form.FilteringSelect"
								name="cboQuestion"
								value="<?php echo html::specialchars($form['cboQuestion']) ?>"
								invalidMessage="กรณาระบุคำถามกันลืม"
								autoComplete="true">
								<?php foreach ($master_questions as $question): ?>
								<option value="<?php echo $question['id']; ?>"><?php echo html::specialchars($question['title']); ?></option>
							    <?php endforeach ?>							
							</select>						
						</td>
					</tr>
					<tr>
						<td>คำตอบ::</td>
						<td>
							<input type="text" name="txtAnswer" value="<?php echo html::specialchars($form['txtAnswer']) ?>"/>
						</td>
					</tr>
					<tr>
						<td><div class="mandatory">ประเภทสมาชิก::</div></td>
						<td>
							<?php foreach ($master_member_types as $member_type): ?>
								<input type="radio" 
									name="rdoMemberType" 
									dojoType="dijit.form.RadioButton" 
									value="<?php echo $member_type['id']; ?>" 
									disabled="disabled" 
								<?php 
									
									if (empty($form['rdoMemberType'])) { 
										echo ($member_type['id']==1)? 'checked="checked"' : ''; 
									}
									else {
										echo ($member_type['id']==$form['rdoMemberType'])? 'checked="checked"' : '';
									} 
								?>>
								<?php echo html::specialchars($member_type['title']); ?>
								</input>
							<?php endforeach ?>						
						</td>
					</tr>
					<tr>
						<td>รูปภาพ::</td>
						<td>
							<?php
								if (!empty($form['txtPicture'])) {
									echo '<img id=imgProfilePicture  alt="'. html::specialchars($form['txtPicture']) .'" src="'. url::base() . html::specialchars($form['txtPicture']) .'" />';
									echo '<br/>';
								} 
								$attributes = array('name' => 'txtPicture');
								echo form::upload($attributes, '');	
							?>					
						</td>
					</tr>									
				</table>
			</div>
			<div id="profileBlockBot">
				<input type="submit" id="btnSave" name="btnSave" value="บันทึก" />
				<input type="button" id="btnCancel" name="btnCancel" value="ยกเลิก" />
			</div>
		</div>
	<?php print form::close(); ?>
	<div id="profileGene">
		<table>
			<tr>
				<h3>แนวเพลง</h3>
				<td>
					<select style="width:80px"
						dojoType="dijit.form.FilteringSelect"
						id="cboGene"
						name="cboGene"
						invalidMessage="กรณาเลือกแนวเพลง"
						autoComplete="true">
						<?php foreach ($genes as $gene): ?>
						<option value="<?php echo $gene['id']; ?>"><?php echo html::specialchars($gene['name']); ?></option>
					    <?php endforeach ?>							
					</select>				
				</td>
				<td>
					<input type="button" id="btnAddGene" name="btnAddGene" value="เพิ่มแนวเพลง" />
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<div id="selectedGenes">
						<table>
						<?php foreach ($profile_genes as $profile_gene): ?>
							<tr>
								<td><?php echo html::specialchars($profile_gene['name']); ?></td>
								<td>
									<a class='actionDelGene' href="<?php echo url::base(); ?>/index.php/member/profile/del_gene/<?php echo $profile_gene['gene_id']; ?>" ><img alt="ลบ" src="<?php echo url::base();?>/media/images/delete.png"/></a>
								</td>
							</tr>
			    		<?php endforeach ?>								
						</table>
					</div>
				</td>
			</tr>
		</table>		 
	</div>
	<div id="profileClub">
		<table>
			<tr>
				<h3>คลับเพลง</h3>
				<td>
					<select style="width:80px"
						dojoType="dijit.form.FilteringSelect"
						id="cboClub"
						name="cboClub"
						invalidMessage="กรณาเลือกคลับเพลง"
						autoComplete="true">
						<?php foreach ($clubs as $club): ?>
						<option value="<?php echo $club['id']; ?>"><?php echo html::specialchars($club['name']); ?></option>
					    <?php endforeach ?>							
					</select>				
				</td>
				<td>
					<input type="button" id="btnAddClub" name="btnAddClub" value="เข้าร่วมคลับเพลง" />
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<div id="selectedClubs">
						<table>
						<?php foreach ($profile_clubs as $profile_club): ?>
							<tr>
								<td><?php echo html::specialchars($profile_club['name']); ?></td>
								<td>
									<a class='actionDelClub' href="<?php echo url::base(); ?>/index.php/member/profile/del_club/<?php echo $profile_club['club_id']; ?>" ><img alt="ลบ" src="<?php echo url::base();?>/media/images/delete.png"/></a>
								</td>
							</tr>
			    		<?php endforeach ?>								
						</table>
					</div>
				</td>
			</tr>
		</table>		 
	</div>
	<div id="profileError">
		<?php 
		echo "<div id='errName' class='profileBlockError'>";
		foreach ($errors as $error):
			echo html::specialchars($error); 
			echo '<br/>';
		endforeach; 
		echo "</div>";
		?>				
	</div>
</div>
